package cn.iocoder.yudao.module.promotion.redpacket.mq;

import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.module.api.promotion.redpacket.message.RedPacketGrantMessage;
import cn.iocoder.yudao.module.api.promotion.redpacket.message.RedPacketUsageMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 店铺红包 事件生产者
 *
 * @author 山野羡民
 */
@Slf4j
@Component
public class RedPacketProducer {

    /**
     * 发送 {@link RedPacketGrantMessage} 消息
     *
     * @param shopId 店铺编号
     * @param userId 用户编号
     * @param amount 红包金额，单位为分
     * @param relatedId 关联的红包记录编号
     * @param remark 关联的红包记录备注
     */
    public void sendRedPacketGrantMessage(Long shopId, Long userId, Integer amount, Long relatedId, String remark) {
        log.info("[sendRedPacketGrantMessage][shopId({}) userId({}) amount({})]", shopId, userId, amount);
        SpringUtil.getApplicationContext().publishEvent(new RedPacketGrantMessage(shopId, userId, amount, relatedId, remark));
    }

    /**
     * 发送 {@link RedPacketUsageMessage} 消息
     *
     * @param shopId 店铺编号
     * @param userId 用户编号
     * @param amount 红包金额，单位为分
     * @param tradeNo 交易单号
     */
    public void sendRedPacketUsageMessage(Long shopId, Long userId, Integer amount, String tradeNo) {
        log.info("[sendRedPacketUsageMessage][shopId({}) userId({}) amount({})]", shopId, userId, amount);
        SpringUtil.getApplicationContext().publishEvent(new RedPacketUsageMessage(shopId, userId, amount, tradeNo));
    }

}
